package com.suredy.app.notice.model;

import java.util.Calendar;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.Transient;

import com.suredy.core.model.BaseFlowModel;

/**
 * 公告模型
 * 
 * @author VIVID.G
 * @since 2015-4-13
 * @version v0.1
 */
@Entity
@Table(name = "t_app_notice")
public class Notice extends BaseFlowModel {

	private static final long serialVersionUID = 6068982201635411702L;

	/* 发布日期 */
	private Date publishTime;

	/* 公示期（天） */
	@Column(nullable = false)
	private Integer publicityPeriod;

	/* 公告标题 */
	@Column(length = 200, nullable = false)
	private String title;

	/* 公告内容 */
	@Column(length = 1000)
	private String content;

	/* 附件ID */
	// TODO: 关联张的附件代码
	// @Column()
	// private String fujianId;

	@Transient
	private Boolean inPeriod;

	public Date getPublishTime() {
		return publishTime;
	}

	public void setPublishTime(Date publishTime) {
		this.publishTime = publishTime;
	}

	public Integer getPublicityPeriod() {
		return publicityPeriod;
	}

	public void setPublicityPeriod(Integer publicityPeriod) {
		this.publicityPeriod = publicityPeriod;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public Boolean getInPeriod() {
		return inPeriod;
	}

	public void setInPeriod(Boolean inPeriod) {
		this.inPeriod = inPeriod;
	}

	@Transient
	public boolean isOutOfPeriod() {
		Date publish = null;
		Integer period = null;

		if ((publish = this.getPublishTime()) == null)
			return false;

		if ((period = this.getPublicityPeriod()) == null)
			return true;

		Calendar c = Calendar.getInstance();
		c.setTime(publish);
		c.add(Calendar.DAY_OF_MONTH, period);

		return c.getTime().before(new Date());
	}

}
